<?php
class Admin_Model_ModuleBAO{
	
	// Get all rows
	public function getAllRows()
	{
		$module= new Admin_Model_ModuleDAO();
		$data = $module->getAllRows();
		$xmlString = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?><response></response>';
		$xml = new SimpleXMLElement($xmlString);
		foreach($data as $value){
			$xml->addChild('module_id',$value['module_id']);	
			$xml->addChild('name',$value['name']);
			$xml->addChild('description',$value['description']);	
			$xml->addChild('thumbnail',$value['thumbnail']);	
			$xml->addChild('author',$value['author']);	
			$xml->addChild('email',$value['email']);	
			$xml->addChild('version',$value['version']);	
			$xml->addChild('license',$value['license']);		
		}
		return $xml;

	}

	// Insert
	public function insert($name,$description,$thumbnail,$author,$email,$version,$license) 
	{
		$module= new Admin_Model_ModuleDAO();
		$module->insertdata($name,$description,$thumbnail,$author,$email,$version,$license); 
	}
	public function install($file)
	{
		$db = Zend_Registry::get('connectDb');
		$fp=fopen($file,"r"); 
		$contents = fread ($fp, filesize($file)); 
		fclose($fp);  
		$db = Zend_Registry::get('connectDb');
		$rst= explode("$$", $contents);
	
		foreach ($rst as $row)
		{
			try 
			{
				$result =$db->query($row)or die("Can not create database "); 
			} 
			catch (Exception $e) {
			}
		}
		
	}
	// Delete
	public function delete($name)
	{
		$module = new Admin_Model_ModuleDAO();
		$module->delete($name);
	}
	public function uninstall($file)
	{
		$db = Zend_Registry::get('connectDb');
		$fp=fopen($file,"r"); 
		$contents = fread ($fp, filesize($file)); 
		fclose($fp);  
		$db = Zend_Registry::get('connectDb');
		$rst= explode("$$", $contents);
	
		foreach ($rst as $row)
		{
			try 
			{
				$result =$db->query($row)or die("Can not create database "); 
			} 
			catch (Exception $e) {
			}
		}
		
	}
	
}